﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Interface;
using NetDon.OA.Interface.eLogistics;
using NetDon.OA.Portal.Common;
using NetDon.Utilities;

namespace NetDon.OA.Portal.eLogisticsQuery
{
        [Navigation("报表查询", "客服回单情况统计")]
    public partial class ReceiptInfoQueryPage : PageBase
    {
        protected int? CurrentOrderStatus { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                txtReceiptInfoPlannedResponseDateStart.Text = txtActualShippingDateStart.Text =
                 TimeHelper.GetStartDayOfMonth().ToString("yyyy-MM-dd");
                txtReceiptInfoPlannedResponseDateEnd.Text = txtActualShippingDateEnd.Text =
            TimeHelper.GetEndDayOfMonth().ToString("yyyy-MM-dd");
                txtReceivingOrderDateStart.Text =

 DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
                txtReceivingOrderDateEnd.Text =

             DateTime.Now.ToString("yyyy-MM-dd");

                ddlCompany.InsertEmptyItem(ListEmptyType.Select);
                if (!this.IsSuperRoles())
                {
                    ddlCompany.SelectedValue = CurrentApplicationContext.CompanyId.ToString();
                    ddlCompany.Enabled = false;
                }
            }
        }



        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

        }

        public void btnSearch_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["ReceiptInfoQuery"] = GetSearchCriteria();
            this.ScriptStartup("search();");
        }

        protected ReceiptInfoQueryCriteria GetSearchCriteria()
        {
            var criteria = new ReceiptInfoQueryCriteria
            {

            };
            if (!MiscUtilities.IsNullOrEmpty(ddlCompany.SelectedValue))
            {
                criteria.AreaId = ddlCompany.SelectedValue.ToGuid();
            }
            DateTime? dateStart = null, dateEnd = null;
            if (!MiscUtilities.IsNullOrEmpty(txtReceiptInfoPlannedResponseDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtReceiptInfoPlannedResponseDateStart.Text.Trim());
            }
            if (!MiscUtilities.IsNullOrEmpty(txtReceiptInfoPlannedResponseDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtReceiptInfoPlannedResponseDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.ReceiptInfoPlannedResponseDate = new Range<DateTime?>(dateStart, dateEnd);
            }

            dateStart = null;
            dateEnd = null;
            if (!string.IsNullOrEmpty(txtActualShippingDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtActualShippingDateStart.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtActualShippingDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtActualShippingDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.ActualShippingDate = new Range<DateTime?>(dateStart, dateEnd);
            }
            //出单日期
            dateStart = null;
            dateEnd = null;
            if (!string.IsNullOrEmpty(txtReceivingOrderDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtReceivingOrderDateStart.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtReceivingOrderDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtReceivingOrderDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.ReceivingOrderDate = new Range<DateTime?>(dateStart, dateEnd);
            }


            if (!MiscUtilities.IsNullOrEmpty(ddlRouteTypeId.SelectedValue.ToGuid()))
            {
                criteria.RouteTypeId = ddlRouteTypeId.SelectedValue.ToGuid();
            }


            return criteria;
        }

    }


}